﻿using QFramework;
using System;
using System.Collections;

namespace GameJamLight
{
    public class LoadSceneCommand : AbstractCommand
    {
        private readonly string name;
        private readonly float stepIn, stepOut;
        private readonly Action callback;

        public LoadSceneCommand(string nextName, float stepIn = 0, float stepOut = 0, Action callback = null)
        {
            name = nextName;
            this.stepIn = stepIn;
            this.stepOut = stepOut;
            this.callback = callback;
        }

        protected override void OnExecute()
        {
            this.GetSystem<ITransitionSystem>().Fade(stepIn, stepOut, () =>
            {
                IEnumerator coroutine = this.GetSystem<ISceneMgrSystem>().AsyncLoad(name, callback);
                PublicMono.Instance.StartCoroutine(coroutine);
            });
        }
    }
}
